<!--
 * @Author: 李小晴 2689279066@qq.com
 * @Date: 2023-03-29 11:47:01
 * @LastEditors: 李小晴 2689279066@qq.com
 * @LastEditTime: 2023-08-28 19:10:28
 * @FilePath: \sys\src\views\Asset\Pasture\components\Park.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script setup lang="ts">
import { Form } from '@/components/Form'
import { useForm } from '@/hooks/web/useForm'
import { reactive, ref, PropType, watch } from 'vue'
import { zcParkListApi } from '@/api/sp/park'

const props = defineProps({
  currentRow: {
    type: Object as PropType<Nullable<any>>,
    default: () => null
  }
})

const data: any = ref({})
const schema = reactive<FormSchema[]>([
  {
    field: 'park_id',
    label: '关联园区',
    component: 'DialogRefer',
    componentProps: {
      getListApi: zcParkListApi,
      response: { count: 'count', data: 'data' },
      title: '选择关联园区（双击选择）',
      nameField: 'name',
      relNameField: 'name',
      valueField: 'id',
      crudSchemas: [
        { field: 'name', label: '园区名称', search: { show: true } },
        { field: 'code', label: '园区编码', search: { show: true } }
      ],
      modelName: data.value.name
    }
  }
])

const { register, methods, elFormRef } = useForm({
  schema
})
const init = async () => {
  data.value.id = props.currentRow.park_id ? props.currentRow.park_id : ''
  data.value.name = props.currentRow.park_name ? props.currentRow.park_name : ''
}
init()

watch(
  () => data,
  (value) => {
    if (!value) return
    methods.setValues(data.value)
  },
  {
    deep: true,
    immediate: true
  }
)
defineExpose({
  elFormRef,
  getFormData: methods.getFormData
})
</script>

<template>
  <Form @register="register" />
</template>
